package com.mezz.bones.im.gateway.manager;

import com.mezz.bones.im.common.domain.user.ImUserConnectInfo;
import com.mezz.bones.im.gateway.attr.ChannelAttributes;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.stereotype.Service;

/**
 * @Author: zhuang
 * @Date: 2024/12/5 17:28
 * @Description: TODO
 * @Version: 1.0
 **/

@Service
public class UserConnectInfoManager {

    // 设置用户信息到 ChannelContext  首次连接时设置
    public void setUserConnectInfo(ChannelHandlerContext ctx, ImUserConnectInfo userInfo) {
        ctx.channel().attr(ChannelAttributes.USER_INFO).set(userInfo);
    }

    // 从 ChannelContext 获取用户信息
    public ImUserConnectInfo getUserConnectInfo(ChannelHandlerContext ctx) {
        return ctx.channel().attr(ChannelAttributes.USER_INFO).get();
    }
}
